package com.swing;

import javax.swing.*;
import java.awt.*;

public class HelloWordSwing {
    public static void createGUI() {
        //JFrame指一个窗口，构造方法的参数为窗口标题
        JFrame frame = new JFrame("MY Demo");
        //设置该窗口可关闭
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //内容面板
        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new FlowLayout());

        //像内容面板里添加控件，如JLabel, JButton
        JLabel jLabel = new JLabel("aaaa");
        contentPane.add(new JLabel("Hello World"));
        contentPane.add(new JButton("测试"));
        contentPane.add(jLabel);

        //设置窗口的其他参数，如窗口大小
        frame.setSize(400, 300);
        //显示窗口
        frame.setVisible(true);

    }

    public static void main(String[] args) {
        //此段代码间接地调用了createGUI(),具体原理在Swing高级篇里讲解
        //初学者先照抄框架即可
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                createGUI();
            }
        });
    }

}
